package cn.tedu.baking2023.controller;

import cn.tedu.baking2023.mapper.BakingMapper;
import cn.tedu.baking2023.mapper.ContentMapper;
import cn.tedu.baking2023.pojo.dto.ContentDTO;
import cn.tedu.baking2023.pojo.entity.Content;
import cn.tedu.baking2023.pojo.vo.BakingIndexVO;
import cn.tedu.baking2023.pojo.vo.UserVO;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpSession;
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.UUID;

@Slf4j
@Api(tags = "内容管理模块")
@RestController
public class ContentController {
    @Autowired(required = false)
    ContentMapper contentMapper;
    @Autowired(required = false)
    BakingMapper bakingMapper;

    @ApiOperation("发表内容")
    @ApiOperationSupport(order = 101)
    @PostMapping("/insert")
    public int insert(@RequestBody ContentDTO contentDTO, HttpSession session){
        //从会话对象中得到登录成功时保存的用户对象
        UserVO user = (UserVO) session.getAttribute("user");
        if (user==null){//未登录
            return 2;
        }
        Content c = new Content();
        //复制属性
        BeanUtils.copyProperties(contentDTO,c);
        c.setCreateTime(new Date());
        contentMapper.insert(c);
        return 1;
    }

}